import {  wxlist } from "../../../server/api";
import {captureTime} from '../../../server/pulbmethod'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    list: [],
    pageSize: 10,
    pageNo: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({ list: [], pageNo: 1, pageSize: 10, active: 0 });
    this.getdata();
  },
  //商家申请管理
  async getdata(val) {
    const params = {
      processType: this.data.active,
      pageNo: this.data.pageNo,
      pageSize: this.data.pageSize,
      auditType:1
    };
    const res = await wxlist(params);
    if (res.code == 200) {
      const source = res.result.records.map((item) => {
        item.time = item.applicationTime == null ? '' : captureTime(item.applicationTime);
        return item;
      });
      this.setData({
        list: val == undefined ? source : [...this.data.list, ...source],
      });
    }
  },
  //商家申请和活动上报事件
  onChange(e) {
    const index = e.detail.index;
    this.setData({ active: index });
    this.setData({ list: [], pageNo: 1, pageSize: 10 });
    if (index == 0) {
      this.getdata();
    } else {
      this.getdata();
    }
  },
  //详情
  spdetail(e) {
    const id = e.currentTarget.dataset.id;
    const processType = e.currentTarget.dataset.flag;
    console.log(processType,'processType');
    const type = this.data.active == 0 ? "0" : "4";
    wx.navigateTo({
      url: `../../../subPackagesB/pages/approvaldetail/approvaldetail?flag=${processType}&id=${id}&type=${type}`,
    });
  },
  //分页
  getMore() {
    this.data.pageNo++;
    const params = {
      processType: this.data.active,
      pageNo: this.data.pageNo,
      pageSize: this.data.pageSize,
      auditType:1
    };
    if (this.data.active == 0) {
      this.getdata(params);
    } else {
      this.getdata(params);
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
